import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class ServidorMailsSimple extends ServidorMails {

	public ServidorMailsSimple(String email, String password, String smtp, String puerto) {
		super(email, password, smtp, puerto);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void enviar(Message mensaje) {
		try {
			Transport t = this.session.getTransport("smtp");
			t.connect(this.email, this.password);
            t.sendMessage(mensaje, mensaje.getAllRecipients());
		} catch (NoSuchProviderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public Session getSession() {
		props.put("mail.smtp.host", this.smtp);
        props.put("mail.smtp.port", this.puerto);
        props.put("mail.smtp.auth", true);
        this.session = Session.getDefaultInstance(props);
        return this.session; 
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ServidorMailsSimple serv = new ServidorMailsSimple("mab_787@yahoo.com.ar", "klapaucius+85", "smtp.mail.yahoo.com.ar", "465");
		Message m = new MimeMessage(serv.getSession());
		try {
			m.setSubject("ASUNTO");
			m.setText("MENSAJE");
			m.addRecipient(RecipientType.BCC, new InternetAddress("mab_787@yahoo.com.ar"));
			m.addRecipient(RecipientType.BCC, new InternetAddress("mab_787@hotmail.com"));
			m.addRecipient(RecipientType.TO, new InternetAddress("mbritos@alumnos.exa.unicen.edu.ar"));
			m.addRecipient(RecipientType.BCC, new InternetAddress("matias.rizzi@gmail.com"));
			m.setFrom(new InternetAddress("mab_787@hotmail.com"));
			serv.enviar(m);
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}


}
